"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var permission_service_1 = require("../../../lib/service/admin/permission.service");
var permission_1 = require("./permission");
var PermissionComponent = /** @class */ (function () {
    function PermissionComponent(router, permissionService) {
        this.router = router;
        this.permissionService = permissionService;
        this.currentPage = 1;
        this.itemsPerPage = 12;
        this.isShow = false;
        this.permissionList = new permission_1.PermissionList();
        this.permissionInfo = new permission_1.PermissionInfo();
        this.addPermission = new permission_1.AddPermission();
        this.editPermission = new permission_1.EditPermission();
        this.name = '';
        this.model = '';
        this.orderField = '';
        this.orderSort = '';
    }
    PermissionComponent.prototype.ngOnInit = function () {
        this.getPermissionList();
    };
    PermissionComponent.prototype.getPermissionList = function () {
        var _this = this;
        this.permissionService.getPermissionList(this.name, this.model, this.orderField, this.orderSort, this.currentPage, this.itemsPerPage).subscribe(function (data) {
            if (data.code === 2000) {
                _this.permissionList.list = data.data.data;
                //this.currentPage = data.data.currentPage;
                _this.totalItems = data.data.total;
            }
        });
    };
    PermissionComponent.prototype.getPermissionInfo = function (id) {
        var _this = this;
        this.permissionService.getPermissionInfo(id).subscribe(function (data) {
            if (data.code === 2000) {
                _this.permissionInfo = data.data;
            }
        });
    };
    PermissionComponent.prototype.addPermissionSubmit = function () {
        var _this = this;
        this.permissionService.addPermission(this.addPermission).subscribe(function (data) {
            if (data.code === 2000) {
                _this.type = 'success';
                _this.message = '添加成功';
                _this.isShow = true;
                _this.addModal.hide();
                _this.getPermissionList();
            }
        });
    };
    PermissionComponent.prototype.editPermissionSubmit = function () {
        var _this = this;
        this.editPermission.id = this.permissionInfo.id;
        this.editPermission.name = this.permissionInfo.name;
        this.editPermission.slug = this.permissionInfo.slug;
        this.editPermission.description = this.permissionInfo.description;
        this.editPermission.model = this.permissionInfo.model;
        this.editPermission.orderby = this.permissionInfo.orderby;
        this.permissionService.editPermission(this.editPermission).subscribe(function (data) {
            if (data.code === 2000) {
                _this.type = 'success';
                _this.message = '修改成功';
                _this.isShow = true;
                _this.editModal.hide();
                _this.getPermissionList();
            }
        });
    };
    PermissionComponent.prototype.delPermission = function (id) {
        var _this = this;
        this.permissionService.delPermission(id).subscribe(function (data) {
            if (data.code === 2000) {
                _this.type = 'success';
                _this.message = '删除成功';
                _this.isShow = true;
                _this.getPermissionList();
            }
        });
    };
    /*pageChanged(event: any): void {

    }*/
    PermissionComponent.prototype.pageChanged = function (event) {
        window.scrollTo(0, 0);
        this.currentPage = event.page;
        this.getPermissionList();
        //this.getTemplateTypeList(event.page,this.searchData)
    };
    PermissionComponent.prototype.promptIsShow = function (event) {
        this.isShow = event;
    };
    __decorate([
        core_1.ViewChild('addModal')
    ], PermissionComponent.prototype, "addModal", void 0);
    __decorate([
        core_1.ViewChild('editModal')
    ], PermissionComponent.prototype, "editModal", void 0);
    PermissionComponent = __decorate([
        core_1.Component({
            selector: 'app-permission',
            templateUrl: './permission.component.html',
            styleUrls: ['./permission.component.scss'],
            providers: [permission_service_1.PermissionService]
        })
    ], PermissionComponent);
    return PermissionComponent;
}());
exports.PermissionComponent = PermissionComponent;
